package com.demo.rabbitmq.producer;

import com.demo.rabbitmq.config.DirectExchangeEnum;
import com.demo.rabbitmq.config.DirectQueueEnum;
import com.demo.rabbitmq.config.DirectRoutingKeyEnum;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class ClusterDirectProducer {

    @Resource
    private RabbitTemplate rabbitTemplate;

    public void send(int i) {
        String exchange = DirectExchangeEnum.DIRECT_EXCHANGE.getExchangeName();
        String routingKey = DirectRoutingKeyEnum.CLUSTER_DIRECT_QUEUE_ROUTING_KEY.getRoutingKeyName();
        String content = String.format("消息=%d，hello world! 当前时间：%s", i, new Date());
        rabbitTemplate.convertAndSend(exchange, routingKey, content);
    }

    public void sendMirror(int i) {
        String exchange = DirectExchangeEnum.DIRECT_EXCHANGE.name().toLowerCase();
        String routingKey = DirectRoutingKeyEnum.MIRROR_DIRECT_QUEUE_ROUTING_KEY.getRoutingKeyName();
        String content = String.format("消息=%d，镜像队列 hello world! 当前时间：%s", i, new Date());
        rabbitTemplate.convertAndSend(exchange, routingKey, content);
    }
}
